﻿#region Using namespaces

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using AvalonDock;

#endregion

namespace BOL.Apps.GeneNetworkBrowser.Controls
{
    public partial class FindPane : DockableContent
    {
        public FindPane()
        {
            InitializeComponent();

            _tbFindGene.Focus();
        }

        private void ButtonFindGeneClick(object sender, RoutedEventArgs e)
        {
            FindGene();
        }   

        private void TextBoxFindGeneKeyEnter(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
                FindGene();
        }

        private void ButtonFindRelationClick(object sender, RoutedEventArgs e)
        {
            FindRelation();
        }

        private void TextBoxFindRelationKeyEnter(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
                FindRelation();
        }

        private string[] Split(string text)
        {
            string delimiter = "\t,;:| ";
            string[] split = text.Split(delimiter.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            return split;
        }

        private void FindGene()
        {
            string[] genes = Split(_tbFindGene.Text);
            foreach (var gene in genes)
                Console.WriteLine(gene);
        }

        private void FindRelation()
        {
            string[] relations = Split(_tbFindRelation.Text);
            foreach (var relation in relations)
                Console.WriteLine(relation);
        }

        private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.Source is TabControl)
            {
                if (_tcFind.SelectedIndex == 0)
                    _tbFindGene.Focus();
                else
                    _tbFindRelation.Focus();
            } 
        }
    }
}
